CS3340:  Intro OOP and Design

Beginning Tips on Android Run Time Errors and What to Do

 

When the emulator repeatedly crashes after you have compiled and it
launched emulator and the it loads the apk (application) and when you
try to run the app-- it means there is a runtime error in the code.
To make sure of it,
1) kill all rualways emulators
2) make sure everything saved and kill eclipse
3) restart eclipse
4) always have on hand a "hello world" app (or any app you know runs)
and try to run that instead in obviously a new emulator
5) if #4 runs you know eclipse + emulator are working
6) now try to run your "problem" app and target the same AVD emulator
7) when you try to run "problem" app the emulator "hangs" (sometimes
you see a "spinning" disk on the screen like it is still loading but
it never stops) this means your code is not working


Solution
----------
0) shut down hung emulator and do a Project -> clean on your project
and rerun. If this doesnt help(still hanfpgs) then move to step number
1
1) try to remember what code you added since the app run last and comment it out
2) keep doing number 1 until the app runs (you will have to kill any
"hung" emulators.
3) now slowly add back code from #1 each time re-run the app to make
sure it is working
4) when you come to a point #3 (adding back a piece of code) causes
the emulator to "hang" there is your run time error.  Fix the code. If
you don't see the problem---  Look at API, materials, and search for
examples  related to this piece of code


Prevention
---------
1) only add a little bit of code between re-running on "emulator"!!!!
This makes finding the problem easier

2) when you first experience a problem, stop and look at your code.
Can you see any logicl errors?

3) try debugging in eclipse to look at variables as you run lines of code.

4) when you see and error message (usually in red) in the eclipse
console window this MAY indicate there is a problem with your code
(however there are some errors like when trying to connect to an
external database and connection is too slow so it times out and
crashes-- where it is not your code but a "system" issue)

5) if #3 or #4 don't help look at class materials, API and search
online and developer forum for examples or problems related to the
recently added small bits of code in number 1 that caused the problem.
 By then even as a new programmer most of your errors will get fixed.
However if all fails-- try to comment out code from #1 and rerun so
works.  Then add back cod very slowly, as slowly as you can, and that
may better show you the problem.  Then you can come to me in office
hours or try email and tell me exactly the lines of code that are
causing the problem.

IMPORTANT
---------------
1) when I refer to run time error in code, now the code can include
use of XML files for layout and strings and other resources you add to
your project ( what if you try to open a local file but forgot to add
the file to your resources--- this would cause a run time error).

2) so when adding these kinds of items immediately test to see app still runs

3) when creating interfaces with interface builder -- add a little to
interface and rerun app each time-- this is a bit overly cautious but
as a new programmer can save you time in avoiding problems

REMEMBER
While sometimes frustrating and time consuming, solving run time
errors will make you a stronger programmer and is unavoidable by all.

 

 

© Lynne Grewe